<template>
  <up-popup :show="show" @close="hidePopup">
    <view class="header">编辑信息</view>
    <scroll-view class="content">
      <up-form class="p-[30rpx]" ref="formRef" labelWidth="100rpx">
        <up-form-item label="内容">
          <up-textarea v-model="formData.content" placeholder="请输入内容"></up-textarea>
        </up-form-item>
        <up-form-item label="图片">
          <up-upload :value="formData.image"></up-upload>
        </up-form-item>
      </up-form>
      
    </scroll-view>
    <view class="footer">
      <up-button type="primary" @click="handleSubmit" shape="circle">确认提交</up-button>
    </view>
  </up-popup>
</template>

<script lang="ts" setup>
import { updateUserInfoApi } from '@/addon/htscrm/api/qywork';
import { ref } from 'vue';

const show = ref(false)
const formData = ref({
  content: '',
  image: ''
})

const emit = defineEmits(['close', 'change'])
function showPopup(value={}) {
  formData.value = {...formData.value, ...value}
  show.value = true;
}
function hidePopup() {
  show.value = false;
  emit('close');
}
async function handleSubmit() {
  await updateUserInfoApi(formData.value)
  emit('change', { ...formData.value })
  uni.showToast({title: '修改成功'})
  show.value = false;
}

defineExpose({
  showPopup
})
</script>

<style lang="scss" scoped>
.flex {
  display: flex;
  .text {
    margin-left: 5rpx;
  }
}
.header {
  padding: 30rpx;
  text-align: center;
  font-size: 30rpx;
  font-weight: bold;
}
.footer {
  padding: 30rpx;
}
</style>
